package com.bolun998300.personal_blog_springboot.controller.background;

import java.util.Collections;
import java.util.List;

import com.bolun998300.personal_blog_springboot.pojo.Blog_Tag;
import com.bolun998300.personal_blog_springboot.service.Blog_TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bolun998300.personal_blog_springboot.pojo.Tag;
import com.bolun998300.personal_blog_springboot.service.TagService;

@RestController
public class TagController {

	
	@Autowired
	private TagService tagService;
	@Autowired
	private Blog_TagService blogTagService;
	
	@GetMapping("/tags")
	public List<Tag> list(){
		List<Tag> tagList = tagService.list();
		for(Tag tag : tagList){
			tag.setBlogNum(blogTagService.countByTagId(tag.getId()));
		}
		Collections.sort(tagList);

		return tagList;
	}
	
}
